package com.example.log.alarm.spy;

//import ch.qos.logback.classic.spi.ILoggingEvent;

import ch.qos.logback.classic.spi.ILoggingEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

/**
 * @program: spring-agent
 * @description: bootstrap
 * @author: zt22328 赵儒定
 * @create: 2023-05-05 13:48
 **/
public class QueuedSpy {

//   private static BlockingQueue<Map<String, Object>> throwableQueue = new ArrayBlockingQueue<>(1000);

   private static BlockingQueue<ILoggingEvent> loggerQueue = new ArrayBlockingQueue<>(1000);

   public static void offer(ILoggingEvent event) {
      loggerQueue.offer(event);
   }

   public static List<ILoggingEvent> getLoggingEvents(Integer max) {
      List<ILoggingEvent> list = new ArrayList<>();
      loggerQueue.drainTo(list, max);
      return list;
   }

   public static List<ILoggingEvent> getLoggingEvents() {
      return getLoggingEvents(1000);
   }

}
